package org.no_ip.martin_springwald.google.api.extension.docs;

/**
 * FileExt (DocsService)
 */
public class FileExt {

	/** title: <br/> title of file */
	private String title;
	/** id: <br/> id of file */
	private String id;
	/** parentIds: <br/> Parent IDs */
	private String[] parentIds;
	/** iteratorStatus: <br/> iteration variable */
	private boolean iteratorStatus;

	/**
	 * getTitle: <p>Getter for title.</p>
	 * @return String
	 */
	public String getTitle() { return this.title; }
	/**
	 * getId: <p>Getter for ID.</p>
	 * @return String
	 */
	public String getId() { return this.id; }
	/**
	 * getParentIds: <p>Getter for Parent IDs.</p>
	 * @return String[]
	 */
	public String[] getParentIds() { return this.parentIds; }
	/**
	 * getIteratorStatus: <p>Getter for iteration variable.</p>
	 * @return boolean
	 */
	public boolean getIteratorStatus() { return this.iteratorStatus; }
	
	/**
	 * setTitle: <p>Setter for title.</p>
	 * @param String title
	 */
	public void setTitle(String title) { this.title = title; }
	/**
	 * setId: <p>Setter for ID.</p>
	 * @param String id
	 */
	public void setId(String id) { this.id = id; }
	/**
	 * setIteratorStatus: <p>Setter for iteration variable.</p>
	 * @param boolean iteratorStatus
	 */
	public void setIteratorStatus(boolean iteratorStatus) { this.iteratorStatus = iteratorStatus; }
	
	// constructors
	/**
	 * FileExt:
	 * <p>
	 * Parameterized Constructor for FileExt. Sets title and id, as well
	 * as clean Parent IDs based on the respective Parent Links. Attribute
	 * iteratorStatus will be set to false.
	 * </p>
	 *
	 * @param String title
	 * @param String id
	 * @param DocumentListEntryLink[] links
	 */
	public FileExt(String title, String id, DocumentsListEntryLink[] links) {
		this.title = title;
		this.id = id;
		String[] parentIds = new String[links.length];
		int cnt = 0;
		for (int i=0; i<links.length; i++) {
			if (links[i].getRel()==DocumentsListEntryLink.REL_PARENT) {
				String href = links[i].getHref();
				href = href.substring(href.lastIndexOf("/")+1); //$NON-NLS-1$
				int idxQS = href.lastIndexOf("?"); //$NON-NLS-1$
				if (idxQS>0) href = href.substring(0, idxQS);
				parentIds[i] = href;
				cnt++;
			}
		}
		this.parentIds = new String[cnt];
		System.arraycopy(parentIds, 0, this.parentIds, 0, cnt);
		this.iteratorStatus = false;
	}
	FileExt() {};
	
}